import {HydSDK} from "../HYDSDK/TTHSDK";

var e = require;
var t = module;
cc.Class({
    extends: cc.Component,
    properties: {
        pb: cc.ProgressBar,
        pbnum: cc.Label,
        yan: cc.Node,
        nextScene: "Menu",
        timeDelay: 2,
        sp_dissolve: [cc.Sprite]
    },
    onLoad: function onLoad() {
        (this.STATE_IN = 0), (this.STATE_OUT = 1), (this.STATE_LOAD = 2), (this.state = -1);
        HydSDK.Init()
    },
    onEnable: function onEnable() {
        (this.timeNow = this.timeDelay), (this.isInLoading = !0), (this.dissolveSpd = 0.5), this.aniIn();
    },
    start: function start() {
        (this.timeNow = this.timeDelay), (this.isInLoading = !0), soundMgr.playBgm(soundMgr.bgm);
    },
    aniIn: function aniIn() {
        (this.state = this.STATE_IN), (this.dissolveValue = 0.25);
    },
    aniOut: function aniOut() {
        (this.state = this.STATE_OUT),
            (this.pb.node.opacity = 0),
            (this.yan.opacity = this.pb.node.opacity),
            (this.dissolveValue = 0);
    },
    update: function update(e) {
        var t = this;
        if (this.state == this.STATE_IN)
            this.dissolveValue > 0 &&
            (this.sp_dissolve.forEach(function (e) {
                e.getMaterial(0).setProperty("noiseThreshold", t.dissolveValue);
            }),
                (this.pb.node.opacity = Math.min(255, 255 - 510 * this.dissolveValue)),
                (this.yan.opacity = this.pb.node.opacity),
                (this.dissolveValue -= this.dissolveSpd * e),
            this.dissolveValue <= 0 && ((this.dissolveValue = 0), (this.state = this.STATE_LOAD)));
        else if (this.state == this.STATE_OUT)
            this.dissolveValue < 1 &&
            (this.sp_dissolve.forEach(function (e) {
                e.getMaterial(0).setProperty("noiseThreshold", t.dissolveValue);
            }),
                (this.dissolveValue += this.dissolveSpd * e),
            this.dissolveValue > 1 && ((this.dissolveValue = 1), this.node.destroy()));
        else if (this.state == this.STATE_LOAD && this.isInLoading) {
            this.timeNow > 0
                ? (this.timeNow -= e)
                : ((this.isInLoading = !1), cc.director.loadScene(this.nextScene)),
            this.timeNow < 0 && (this.timeNow = 0);
            var o = Math.floor(((this.timeDelay - this.timeNow) / this.timeDelay) * 100);
            this.pbnum.string = o + "%";
        }
    }
});
